package diamondServer.clientserver.threadpool;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class PoolManager {
	private ThreadPoolExecutor pool;
	private Collection<Callable<String>> c;
	
	
	public PoolManager() {
	
		pool=new ThreadPoolExecutor (5,10,3, TimeUnit.SECONDS , new LinkedBlockingQueue<Runnable>());
		 c= new LinkedList<Callable<String>>();
		
	}
	
	public void addTask(Task t){
		c.add(t);
	}
	
	
	public List<Future<String>> InvokeAll() throws InterruptedException{
		return pool.invokeAll(c);
	}
	
	public void shutdown(){
		pool.shutdown();
	}

	public void removeAll() {
		c.clear();
		
	}

	public Future<String> submit(Task task) {
		return pool.submit(task);
		
	}
}